import java.util.*;
public class entropya
{
	static int counthash=0,flag1=0,flag2=0;
	static int flag31=0,flag32=0,flag33=0;
	static int counttransaction=0;
	static double H1=0,H2=0,H3=0;
	public static void main(String args[])
	{
		Hashtable<String,double> Hash1 = new Hashtable<String,double> ();
		Hashtable<String,double> Hash2 = new Hashtable<String,double> ();
		Hashtable<String,double> Hash3 = new Hashtable<String,double> ();
		int y = Integer.parseInt(args[0]);
		int min_sup = Integer.parseInt(args[1]);
		FileInputStream fstream = new FileInputStream(args[2]);
		DataInputStream in = new DataInputStream(fstream);
		BufferedReader br = new BufferedReader(new InputStreamReader(in));
		String strLine;
		while ((strLine = br.readLine()) != null)   
		{
			counttransaction++;
			insertintoArray(strLine,y,min_sup);
		}
		calculateentropy(Hash1,Hash2,Hash3,y,counttransaction);
	}
	static void insertintoArray(String strLine,int y,int min_sup)
	{
				String ar[] = strLine.split("\t");
				int n=ar.length;
				calculate(ar[],n,y,min_sup);
	}
	static void calculate(String ar[],int n,int y,int min_sup)
	{
		String arr1[]=new String[n];
		if(y==1)
		{	
			double x=0;
			for(int i1=0;i1<n-1;i1++)
			{
				String key1=ar[i1];
				x=getSupport(ar[i1]);
				if(x>=min_sup)
				{
					Hash1.put(key1,x);
					Enumeration names11;
					names11=Hash1.keys();
					if(names11==0)
					{
						arr1[counthash]=key1;
					}
					else
					{
						while(names11.hasMoreElements())
						{
							counthash++;
							arr1[counthash]=key1;
						}
					}
				
				}
			}
		}
		String arr2[]=new String[n];
		if(y==2)
		{
			double x = 0;
			counthash=0;
			for(int i1 = 0;i1 < arr1.length;i1++)
			{
				for(int i2 = i1 + 1;i2 < arr1.length;i2++)
				{
					String key2 = arr1[i1]+" "+arr1[i2];
					x = getSupport(arr1[i1],arr1[i2]);
					if(x>=min_sup)
					{
						Hash2.put(key2,x);
						Enumeration names22;
						names22=Hash1.keys();
						if(names22==0)
						{
							arr2[counthash]=arr1[i1];
							counthash++;
							arr2[counthash]=arr1[i2];
						}
						else
						{	flag1=0;
							flag2=0;
							while(names22.hasMoreElements())
							{	
								for(int ar=0;ar<=counthash;ar++)
								{
									if(arr2[ar].equals(arr1[i1]))
									{
										flag1=1;
									}
									if(arr2[ar].equals(arr1[i2]))
									{
										flag2=1;
									}
								}
								if(flag1==0)
								{
									counthash++;
									arr2[counthash]=arr1[i1];
								}
								if(flag2==0)
								{
									counthash++;
									arr2[counthash]=arr1[i2];
								}
							}
						}
					}
				}
			}
		}
		if(y==3)
		{	
			double x = 0;
			String x3;
			for(int i1 = 0;i1 <arr2.length;i1++)
			{
				for(int i2 = i1 + 1;i2 < arr2.length;i2++)
				{
					for(int i3 = i2 + 1;i3 < arr2.length;i3++)
					{
						String key3 = arr2[i1]+" "+arr2[i2]+" "+arr2[i3];
						String key31=arr2[i1]+" "+arr2[i2];
						String key32=arr2[i2]+" "+arr2[i3];
						String key33=arr2[i1]+" "+arr2[i3];
						flag31=0;
						flag32=0;
						flag33=0;
						Enumeration names32;
						names32=Hash2.keys();
						while(names32.hasMoreElements())
						{
								x3=(String)names32.nextElement();
								if(x3.equals(key31))
								{
									flag31=1;
								}
								if(x3.equals(key32))
								{
									flag32=1;
								}
								if(x3.equals(key33))
								{
									flag33=1;
								}
						}
						if(flag31==1 && flag32==1 && flag33==1)
						{
							x = getSupport(key31,key32);
							if(x>=min_sup)
							{
								Hash3.put(key3,x);
							}
						}
					}
				}
			}
		}
	}
	static void calculateentropy(Hashtable<String,double> Hash1,Hashtable<String,double> Hash2,Hashtable<String,double> Hash3,int y,int counttransaction)
	{	
		Enumeration names1,names2,names3;
		String str;
		if(y==1)
		{
			names1=Hash1.keys();
			while(names1.hasMoreElements())
			{
				str=(String)names1.nextElement();
				int supp=Hash1.get(str);
				int nprob=supp/(100*counttransaction);
				H1=H1+(nprob*calculatelog(nprob));
			}
			System.out.println("H1 is "+H1);
			
		}
		if(y==2)
		{
			names2=Hash2.keys();
			while(names2.hasMoreElements())
			{
				str=(String)names2.nextElement();
				int supp=Hash2.get(str);
				int nprob=supp/(100*counttransaction);
				H2=H2+(nprob*calculatelog(nprob));
			}
			System.out.println("H2 is "+H2);
			
		}
		if(y==3)
		{
			names3=Hash3.keys();
			while(names3.hasMoreElements())
			{
				str=(String)names3.nextElement();
				int supp=Hash3.get(str);
				int nprob=supp/(100*counttransaction);
				H3=H3+(nprob*calculatelog(nprob));
			}
			System.out.println("H3 is "+H3);
			
		}
	}
	static double calculatelog(double nprob)
	{
		double logvalue=(double)Math.log(nprob)/Math.log(2);
		return (logvalue);
	}
}